package com.db.mylogger;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

public class MyLoggerFactory implements ILoggerFactory {

	Map<String, Logger> loggerMap;
	
	public MyLoggerFactory() {
		loggerMap = new HashMap<String, Logger>();
	}
	
	public synchronized Logger getLogger(String filename) {
		Logger logger = loggerMap.get(filename);
		if(logger != null) {
			return logger;
		}
		try {
			logger = new MyLoggerAdapter(filename);
			loggerMap.put(filename, logger);
			return logger;
		} catch (FileNotFoundException e) {
			System.out.println("[ERROR] : " + new Date() + " cannot find file");
			throw new MyLoggerException();
		} catch (IOException e) {
			System.out.println("[ERROR] : " + new Date() + " cannot find file");
			throw new MyLoggerException();
		}
	}

}
